<script>

    function tjprocess() {

        var url = "/api/post/submit_process";
        var process = $("#process").val();

        var recstate = document.getElementById("recstate");
        var action_data = new FormData();

        action_data.append("user_id", "{{userinfo}}");
        action_data.append("post_id", "{{postinfo.uid}}");
        action_data.append("process_id", process);


        $.ajax({
                type: 'POST',
                url: url,
                data: action_data,
                timeout: 1e3,
                processData: false,
                contentType: false,
                success: function (rs) {

                    recstate.innerHTML = 'Waiting for Review  <a class="btn btn-primary btn-xs" onclick="cancel()">Cancel Review</a>'

                },
                error: function (err) {
                    {#alert('Submission failed');#}
                }
            }
        );


    }
    function cancel() {

        var url = "/api/post/rovoke";

        var recstate = document.getElementById("recstate");
        var action_data = new FormData();

        action_data.append("user_id", "{{userinfo}}");
        action_data.append("post_id", "{{postinfo.uid}}");


        $.ajax({
                type: 'POST',
                url: url,
                data: action_data,
                timeout: 1e3,
                processData: false,
                contentType: false,
                success: function (rs) {

                      recstate.innerHTML = '<select class="form-select" name="process" id="process"> {% for pro in process %}  <option value="{{ pro.uid }}">{{ pro.name }}</option>{% end %}   </select> <button onclick="tjprocess()" class="btn btn-primary btn-sm">{{ _("Submit for review") }}</button>'

                },
                error: function (err) {
                    {#alert('Submission failed');#}
                }
            }
        );


    }
</script>


{% if userinfo  and (userinfo.extinfo.get('_per_can_edit', 0) == 1) %}
{% if postinfo.valid==0 %}
<div class="row">
    <div id="recstate" class="col-sm-5">

        {% if action_arr %}

        {{ _('Waiting for Review') }}

        <a class="btn btn-primary btn-xs" onclick="cancel()">{{ _('Cancel Review') }}</a>
        {% elif process %}


        <select class="form-select" name="process" id="process">
            {% for pro in process %}
            <option value="{{ pro.uid }}">{{ pro.name }}</option>
            {% end %}
        </select>

        <button onclick="tjprocess()" class="btn btn-primary btn-sm">{{ _("Submit for review") }}</button>
        {% else %}

        {% end %}
    </div>
</div>
{% end %}
{% end %}





